﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class admin_CompanyManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Main.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 48)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
        if (!IsPostBack)
        {
            CompanyInfo companyInfo = CompanyInfoManager.showIt(Server.MapPath(@"~/companyFiles/Company.xml"));
            txtAccounts.Text = companyInfo.Accounts;
            txtAddress.Text = companyInfo.Address;
            txtBankAccounts.Text = companyInfo.BankAccounts;
            txtCompanyName.Text = companyInfo.CompanyName;
            txtEmail.Text = companyInfo.Email;
            txtFaxes.Text = companyInfo.Faxes;
            txtPostalcode.Text = companyInfo.Postalcode;
            txtTelephone.Text = companyInfo.Telephone;
            txtURL.Text = companyInfo.Url;
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        CompanyInfo companyInfo = new CompanyInfo();
        companyInfo.Accounts = txtAccounts.Text;
        companyInfo.Address = txtAddress.Text;
        companyInfo.BankAccounts = txtBankAccounts.Text;
        companyInfo.CompanyName = txtCompanyName.Text;
        companyInfo.Email = txtEmail.Text;
        companyInfo.Faxes = txtFaxes.Text;
        companyInfo.Postalcode = txtPostalcode.Text;
        companyInfo.Telephone = txtTelephone.Text;
        companyInfo.Url = txtURL.Text;
        if (CompanyInfoManager.UpdateElement(companyInfo,Server.MapPath(@"~/companyFiles/Company.xml")))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改成功！')", true);
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('修改失败！请重试！')", true);
        }
    }
}
